package com.simple.config.searchengine;

import com.simple.entity.cosntant.AdiConstant;
import com.simple.interfaces.AbstractSearchEngineService;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @desc
 * @Author Simple
 * @Date 2025/7/8 22:13
 **/
@Slf4j
public class SearchEngineServiceContext {

    public static final Map<String, AbstractSearchEngineService<?>> NAME_TO_SEARCHER = new LinkedHashMap<>();

    private SearchEngineServiceContext() {
    }

    public static void addWebSearcher(String engineName, AbstractSearchEngineService<?> searcher) {
        NAME_TO_SEARCHER.put(engineName, searcher);
    }

    public static AbstractSearchEngineService<?> getService(String searcherName) {
        AbstractSearchEngineService<?> searcher = NAME_TO_SEARCHER.get(searcherName);
        return Objects.isNull(searcher) ? NAME_TO_SEARCHER.get(AdiConstant.SearchEngineName.GOOGLE) : searcher;
    }

    public static Map<String, AbstractSearchEngineService<?>> getAllService() {
        return NAME_TO_SEARCHER;
    }
}
